<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>增加银行卡</title>
		<script type="text/javascript" src="../../js/jquery-3.2.1.min.js" ></script>
		<script type="text/javascript" src="../../js/common.js" ></script>
	</head>
	<body >
		
		<p >银行卡的列表</p>
		
		<table>
			<tr>
				<td>
					<input type="button" value="增加" onclick="addCard();">
				</td>
				
				<td>
					<input type="button" value="修改" onclick="updateCard();">
				</td>
				<td>
					<input type="button" value="删除" onclick="deleteCard();">
				</td>
			</tr>
		</table>
		<table border="1" cellpadding="0" cellspacing="0"  width="500">
			<tr>
				<th><input type="checkbox" id="selectAllCheckBox" /></th>
				<th>银行名称</th>
				<th>卡号</th>
				<th>有无芯片</th>
				<th>余额</th>
				<th>银行卡持有人</th>
			</tr>
			
			<tbody id="card-list">
			
			</tbody>
			
		</table>
		
		<script>
			
		
		function addCard(){
			window.location.href='card-add.html';
			
		}
		
		 //1修改方法开始
		 function updateCard(){
			 
			 //1 拿到id 往后面传
			 
			 var cks  = $('input[type="checkbox"]:checked');
			 
			 if(cks.length ==1){
				 
				 var val = cks.val();
				 
				 if(val != 'on'){
					 //alert(val);
					 window.location.href='card-update.jsp?id='+val;
					 
				 }else{
					 alert("请选中一行有效的被修改的页面...");
				 }
			 }else{
				 alert("请选中一行有效的被修改的页面...");
			 }
			 
			 //window.location.href='card-update.html';
		 }
		 
		 //1修改方法结束
			
			
			
			
			
			
			//页面一加载的时候就发送ajax请求
			$(function(){
				
				//1 发送ajax请求获得所有的部门
				$.ajax({
					async:true,
					data:{
						'method':'findAllCards'
					},
					url:getPath()+"/card",
					type:'post',
					dataType:'json',
					success:function(jsonData){
						
						var  code  = jsonData.result.code;
						
						if(code == '200'){
							
							//把银行要动态话
							
							
							
							
							//CTRL + K
							var tbody= $('#card-list');
							
							var data = jsonData.data;
							
							$(data).each(function(index,data){
								
								console.log(data);
								
								var valueField = data.valueField;
								var textField  = data.textField;
								
								
								//<input type="checkbox" var />
								//<td>银行名称</td>
								//<td>卡号</td>
								//<td>有无芯片</td>
								//<td>余额</td>
								//<td>银行卡持有人</td>
								
								var id = data.id;
								var idRow = '<td><input type="checkbox" value="'+id+'" /></td>';
								
								var bankName = data.bankName;
								var bankNameRow = '<td>'+bankName+'</td>';
								
								var cardNo = data.cardNo;
								var cardNoRow = '<td>'+cardNo+'</td>';
								
								var chipName = data.chipName;
								var chipNameRow = '<td>'+chipName+'</td>';
								
								var balance = data.balance;
								var balanceRow = '<td>'+balance+'</td>';
								
								
								var owner = data.owner;
								var ownerRow = '<td>'+owner+'</td>';
								
								var tr = $('<tr></tr>');
								tr.append($(idRow));
								tr.append($(bankNameRow));
								tr.append($(cardNoRow));
								tr.append($(chipNameRow));
								tr.append($(balanceRow));
								tr.append($(ownerRow));
								
								tbody.append(tr);
								
							});
							
							
						}
					}
				});
				
				
				
			});
			
		</script>
	</body>
</html>